package quickstart;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * Created by huangyu on 2018/9/22 23:58
 */
public class Producer {

	public static void main(String[] args) throws Exception {
		// 1.创建一个连接工厂，并配置连接地址
		ConnectionFactory connectionFactory = new ConnectionFactory();
		connectionFactory.setHost("192.168.177.128");
		connectionFactory.setPort(5672);
		connectionFactory.setVirtualHost("/");
		// 2.创建连接
		Connection connection = connectionFactory.newConnection();
		// 3.创建一个通道
		Channel channel = connection.createChannel();
		for (int i = 0; i < 5; i++) {
			// 4.通过通道发送数据
			channel.basicPublish("", "test001", null, "Hello RabbitMq".getBytes());
		}
		// 4.关闭连接
		channel.close();
		connection.close();
	}
}
